/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        vector<int> v1(100);
        vector<int> v2(100);
        int i = 0;
        while (l1)
        {
            v1[i] = l1->val;
            //cout<<l1->val<<" ";
            l1 = l1->next;
            i++;

        }
        i = 0;
        while (l2)
        {
            v2[i] = l2->val;
            //cout<<l1->val<<" ";
            l2 = l2->next;
            i++;
        }
        reverse(v1.begin(), v1.end());
        reverse(v2.begin(), v2.end());




        int end = 99;
        vector<int> v(101);
        while (end >= 0)
        {

            v[end + 1] = v1[end] + v2[end];
            end--;
        }

        for (int i = 100;i >= 1;i--)
        {
            //cout<<v[i];
            v[i - 1] += v[i] / 10;
            v[i] %= 10;
        }
        // for(auto e:v) cout<<e<<" ";
        ListNode* head = new ListNode;
        int j = 0;
        while (j <= 100 && v[j] == 0)
        {
            j++;
        }
        if (j == 101)
        {
            return new ListNode(0);
        }
        while (j <= 100)
        {
            ListNode* tmp = new ListNode(v[j]);
            tmp->next = head->next;
            head->next = tmp;
            j++;

        }

        return head->next;





    }
};